﻿using AntdUI;
using Super.Admin.Utils;
using Super.Admin.Utils.ThemeManager;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Super.Admin.Views.Login
{
    public partial class UcLoginSetting : UserControl
    {
        public UcLoginSetting()
        {
            InitializeComponent();
            InitializeBtnLoginLayout(); // 初始化登录布局选项
            InitializeBtnLanguage(); // 设置语言选项
            InitializeBtnSetThemeIconSvg(); // 初始化主题切换图标
            ColorPicker.Value = ColorTranslator.FromHtml(ThemeSettingHelper.Instance.ThemeConfig.AppearanceSettings.BuiltInThemes.PrimaryColor); // 初始化颜色
        }
        /// <summary>
        /// 初始化登录布局选项
        /// </summary>
        private void InitializeBtnLoginLayout()
        {
            BtnLoginLayout.Items.AddRange(new ISelectItem[]
            {
                new SelectItem(Properties.Resources.Right,"居右","Right"),
                new SelectItem(Properties.Resources.Center,"居中","Center"),
                new SelectItem(Properties.Resources.Left,"居左","Left"),
            });
            string layout = "Right";
            switch (ThemeSettingHelper.Instance.ThemeConfig.LayoutSettings.LoginLayout.LoginLayoutType)
            {
                case LoginLayoutType.Center:
                    layout = "Center";
                    break;
                case LoginLayoutType.Left:
                    layout = "Left";
                    break;
            }
            BtnLoginLayout.SelectedValue = layout;
        }
        private void BtnLoginLayout_SelectedValueChanged(object sender, ObjectNEventArgs e)
        {
            if (BtnLoginLayout.SelectedValue != null)
            {
                ThemeSettingHelper.Instance.ThemeConfig.LayoutSettings.LoginLayout.LoginLayoutType = Enum.Parse<LoginLayoutType>(BtnLoginLayout.SelectedValue.ToString());
            }
            else
            {
                Growl.Warning("请选择一个有效的登录布局选项");
            }
        }

        /// <summary>
        /// 初始化语言选项
        /// </summary>
        private void InitializeBtnLanguage()
        {
            BtnLanguage.Items.AddRange(new ISelectItem[]
            {
                new SelectItem("中文","Chinese"),
                new SelectItem("English","English"),
                new SelectItem("日本語","Japanese"),
            });
            string lang = "Chinese";
            switch (ThemeSettingHelper.Instance.ThemeConfig.GeneralSettings.General.Language)
            {
                case LanguageType.English:
                    lang = "English";
                    break;
                case LanguageType.Japanese:
                    lang = "Japanese";
                    break;
            }
            BtnLanguage.SelectedValue = lang;
        }


        // 设置主题
        private void BtnSetTheme_Click(object sender, EventArgs e)
        {
            if (ThemeSettingHelper.Instance.ThemeConfig.AppearanceSettings.Theme.ThemeType == TAMode.Light)
            {
                ThemeSettingHelper.Instance.SwitchThemeDrakOrLight(TAMode.Dark);
            }
            else
            {
                ThemeSettingHelper.Instance.SwitchThemeDrakOrLight(TAMode.Light);
            }
            InitializeBtnSetThemeIconSvg();
        }

        private void InitializeBtnSetThemeIconSvg()
        {
            BtnSetTheme.IconSvg = ThemeSettingHelper.Instance.ThemeConfig.AppearanceSettings.Theme.ThemeType == TAMode.Light
                ? "Admin.DarkThemes"
                : "Admin.LightThemes";
        }

        private void BtnLanguage_SelectedValueChanged(object sender, AntdUI.ObjectNEventArgs e)
        {
            if (BtnLanguage.SelectedValue != null)
            {
                ThemeSettingHelper.Instance.ThemeConfig.GeneralSettings.General.Language = Enum.Parse<LanguageType>(BtnLanguage.SelectedValue.ToString());
            }
            else
            {
                Growl.Warning("请选择一个有效的语言选项");
            }
        }

        /// <summary>
        /// 设置主题颜色
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ColorPicker_ValueChanged(object sender, ColorEventArgs e)
        {
            ThemeSettingHelper.Instance.SwitchThemeColor(Enums.ThemeColorType.Primary, e.Value.Name);
        }
    }
}
